# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import re

REQUIRED_HEADERS = {'metric_name', 'metric_type', 'orientation', 'integration'}

OPTIONAL_HEADERS = {
    'description',
    'interval',
    'unit_name',
    'per_unit_name',
    'short_name',
    'curated_metric',
}

EXPERIMENTAL_HEADER = {"sample_tags"}
ALL_HEADERS = REQUIRED_HEADERS | OPTIONAL_HEADERS | EXPERIMENTAL_HEADER
HEADERS_TO_CHECK = REQUIRED_HEADERS | OPTIONAL_HEADERS

ORDERED_HEADERS = [
    "metric_name",
    "metric_type",
    "interval",
    "unit_name",
    "per_unit_name",
    "description",
    "orientation",
    "integration",
    "short_name",
    "curated_metric",
    "sample_tags",
]

VALID_METRIC_TYPE = {'count', 'gauge', 'rate'}

VALID_ORIENTATION = {'0', '1', '-1'}

VALID_CURATED_METRIC_TYPES = {'cpu', 'memory'}

VALID_TIME_UNIT_NAMES = {
    'nanosecond',
    'microsecond',
    'millisecond',
    'second',
    'minute',
    'hour',
    'day',
    'week',
}

# To easily derive these again in future, copy the contents of `integration/system/units_catalog.csv` then run:
#
# pyperclip.copy('\n'.join("    '{}',".format(line.split(',')[2]) for line in pyperclip.paste().splitlines()))
VALID_UNIT_NAMES = {
    'name',
    'bit',
    'byte',
    'kilobyte',
    'kibibyte',
    'megabyte',
    'mebibyte',
    'gigabyte',
    'gibibyte',
    'terabyte',
    'tebibyte',
    'petabyte',
    'pebibyte',
    'exabyte',
    'exbibyte',
    'microsecond',
    'millisecond',
    'second',
    'minute',
    'hour',
    'day',
    'week',
    'fraction',
    'percent',
    'connection',
    'request',
    'process',
    'file',
    'buffer',
    'inode',
    'sector',
    'block',
    'packet',
    'segment',
    'response',
    'message',
    'payload',
    'core',
    'thread',
    'table',
    'index',
    'lock',
    'transaction',
    'query',
    'row',
    'hit',
    'miss',
    'eviction',
    'dollar',
    'cent',
    'error',
    'host',
    'node',
    'key',
    'command',
    'offset',
    'page',
    'read',
    'write',
    'occurrence',
    'event',
    'time',
    'unit',
    'operation',
    'item',
    'record',
    'object',
    'cursor',
    'assertion',
    'fault',
    'percent_nano',
    'get',
    'set',
    'scan',
    'nanosecond',
    'service',
    'task',
    'worker',
    'resource',
    'document',
    'shard',
    'flush',
    'merge',
    'refresh',
    'fetch',
    'garbage collection',
    'timeout',
    'hertz',
    'kilohertz',
    'megahertz',
    'gigahertz',
    'email',
    'datagram',
    'column',
    'apdex',
    'instance',
    'sample',
    'commit',
    'wait',
    'ticket',
    'split',
    'stage',
    'monitor',
    'location',
    'check',
    'question',
    'route',
    'session',
    'entry',
    'attempt',
    'cpu',
    'device',
    'update',
    'method',
    'job',
    'container',
    'execution',
    'throttle',
    'invocation',
    'user',
    'degree celsius',
    'degree fahrenheit',
    'success',
    'nanocore',
    'microcore',
    'millicore',
    'kilocore',
    'megacore',
    'gigacore',
    'teracore',
    'petacore',
    'exacore',
    'build',
    'prediction',
    'heap',
    'volume',
    'watt',
    'kilowatt',
    'megawatt',
    'gigawatt',
    'terawatt',
    'view',
    'microdollar',
    'euro',
    'pound',
    'penny',
    'yen',
    'milliwatt',
    'microwatt',
    'nanowatt',
    'ampere',
    'milliampere',
    'volt',
    'millivolt',
    'deciwatt',
    'decidegree celsius',
    'span',
    'exception',
    'run',
    'hop',
    'alert',
    'token',
    'step',
    'nanojoule',
    'millijoule',
    'joule',
    'kilojoule',
    'megajoule',
    "bit_in_bits_family",
    "byte_in_bits_family",
    "kilobit",
    "megabit",
    "gigabit",
    "terabit",
    "petabit",
    "exabit",
    "afghani",
    "lek",
    "algerian dinar",
    "kwanza",
    "east caribbean dollar",
    "argentine peso",
    "armenian dram",
    "aruban florin",
    "australian dollar",
    "azerbaijan manat",
    "bahamian dollar",
    "bahraini dinar",
    "taka",
    "barbados dollar",
    "belarusian ruble",
    "belize dollar",
    "cfa franc bceao",
    "bermudian dollar",
    "indian rupee",
    "ngultrum",
    "boliviano",
    "mvdol",
    "convertible mark",
    "pula",
    "norwegian krone",
    "brazilian real",
    "brunei dollar",
    "bulgarian lev",
    "burundi franc",
    "cabo verde escudo",
    "riel",
    "cfa franc beac",
    "canadian dollar",
    "cayman islands dollar",
    "chilean peso",
    "unidad de fomento",
    "yuan renminbi",
    "colombian peso",
    "unidad de valor real",
    "comorian franc",
    "congolese franc",
    "new zealand dollar",
    "costa rican colon",
    "cuban peso",
    "convertible peso",
    "netherlands antillean guilder",
    "czech koruna",
    "danish krone",
    "djibouti franc",
    "dominican peso",
    "egyptian pound",
    "el salvador colón",
    "nakfa",
    "lilangeni",
    "ethiopian birr",
    "falkland islands pound",
    "fiji dollar",
    "cfp franc",
    "dalasi",
    "lari",
    "ghana cedi",
    "gibraltar pound",
    "quetzal",
    "guinean franc",
    "guyana dollar",
    "gourde",
    "lempira",
    "hong kong dollar",
    "forint",
    "iceland króna",
    "rupiah",
    "iranian rial",
    "iraqi dinar",
    "new israeli sheqel",
    "jamaican dollar",
    "jordanian dinar",
    "tenge",
    "kenyan shilling",
    "north korean won",
    "won",
    "kuwaiti dinar",
    "som",
    "lao kip",
    "lebanese pound",
    "loti",
    "rand",
    "liberian dollar",
    "libyan dinar",
    "swiss franc",
    "pataca",
    "denar",
    "malagasy ariary",
    "malawi kwacha",
    "malaysian ringgit",
    "rufiyaa",
    "ouguiya",
    "mauritius rupee",
    "mexican peso",
    "mexican unidad de inversion (udi)",
    "moldovan leu",
    "tugrik",
    "moroccan dirham",
    "mozambique metical",
    "kyat",
    "namibia dollar",
    "nepalese rupee",
    "córdoba oro",
    "naira",
    "omani rial",
    "pakistan rupee",
    "balboa",
    "kina",
    "guaraní",
    "sol",
    "philippine peso",
    "złoty",
    "qatari rial",
    "romanian leu",
    "russian ruble",
    "rwanda franc",
    "saint helena pound",
    "tālā",
    "dobra",
    "saudi riyal",
    "serbian dinar",
    "seychelles rupee",
    "leone",
    "singapore dollar",
    "sucre",
    "solomon islands dollar",
    "somali shilling",
    "south sudanese pound",
    "sri lanka rupee",
    "sudanese pound",
    "surinam dollar",
    "swedish krona",
    "wir euro",
    "wir franc",
    "syrian pound",
    "new taiwan dollar",
    "somoni",
    "tanzanian shilling",
    "baht",
    "pa’anga",
    "trinidad and tobago dollar",
    "tunisian dinar",
    "turkish lira",
    "new turkmen manat",
    "uganda shilling",
    "hryvnia",
    "uae dirham",
    "us dollar (next day)",
    "peso uruguayo",
    "uruguayo peso en unidades indexadas (ui)",
    "unidad previsional",
    "uzbekistan sum",
    "vatu",
    "bolívar soberano",
    "bolívar digital",
    "đồng",
    "yemeni rial",
    "zambian kwacha",
    "zimbabwe gold",
    "bit_in_decimal_bytes_family",
    "byte_in_decimal_bytes_family",
    "bit_in_binary_bytes_family",
    "byte_in_binary_bytes_family",
}

ALLOWED_PREFIXES = ('system.', 'jvm.', 'http.', 'datadog.', 'sftp.', 'process.', 'runtime.', 'otelcol_')
PROVIDER_INTEGRATIONS = {'openmetrics', 'prometheus'}

MAX_DESCRIPTION_LENGTH = 400

METRIC_REPLACEMENT = re.compile(r"([^a-zA-Z0-9_.]+)|(^[^a-zA-Z]+)")
METRIC_DOTUNDERSCORE_CLEANUP = re.compile(r"_*\._*")
